import { GModalForm, GTable } from 'geminis-react';
import { useRef } from 'react';
import { message } from 'antd';

export default () => {
  const tableRef = useRef<any>();

  const schema = {
    headerTitle: '采购发货信息',
    data: {
      url: '/api/warehouse/purchase/purchase',
      filter: { state: 'PLAN' },
      include: ['routes'],
      sort: 'planTime:desc',
    },
    action: {
      row: {
        render: (record: any) => [
          <GModalForm
            key={record.id}
            button={{
              text: '发货',
              button: {
                type: 'link',
              },
            }}
            form={{
              schema: {
                data: {
                  url: '/api/warehouse/purchase/purchase/delivery',
                  methodSubmit: 'post',
                  format: 'form',
                },
              },
              schemaPath: '/warehouse-pc/schema/purchase/delivery/form.json',
              onSubmitting: (value) => {
                value.ids = [record.id];
              },
              onSubmitted: () => {
                message.success('成功');
                tableRef.current.loadData();
              },
            }}
          />,
        ],
      },
    },
  };

  return (
    <GTable
      ref={tableRef}
      schema={schema}
      schemaPath="/warehouse-pc/schema/purchase/delivery/table.json"
    />
  );
};
